#include "main.h"
#define USART2_LEN 1024
typedef struct {
	uint16_t RX_Size;          //receive length
	uint8_t RX_pData[USART2_LEN]; //DMA receive buffer
} USART2_RECEIVETYPE;
extern USART2_RECEIVETYPE Usart2_Type;
extern USART2_RECEIVETYPE usart2_rx;

#define CHAR_NUM 3
#define CHAR_LEN 48
struct cmd_para {
	uint8_t arg_num;
	char key_char[CHAR_NUM][CHAR_LEN];
};
extern struct cmd_para cmd_para_st;

typedef enum {
	Normal = 0, Failure = 1,
} Mod_Status;
struct Model_WorkState {
	Mod_Status ModelToMCU;
	Mod_Status NetRegister;
	Mod_Status MqttConnect;
	Mod_Status NetClock;
	Mod_Status MqttPub;
	Mod_Status NetAddr;
};
extern struct Model_WorkState module_status;
typedef enum {
	NOT = 0x00, 	//
	GET = 0x01, 		//
	CORRECT = 0x02, //
	WRONG = 0x04, 	//
} RX_STATE;
typedef struct {
	RX_STATE CEREG;
	RX_STATE QMTOPEN;
	RX_STATE QMTCONN;
	RX_STATE QMTPUB;
	RX_STATE QMTSUB;
	RX_STATE QMTRECV;
	RX_STATE Greater;
	RX_STATE CCLK;
	RX_STATE QDNS;
	RX_STATE NSONMI;
	RX_STATE CGATT;
	RX_STATE topUp;
} RX_receiveState;
extern RX_receiveState receive_state;

#define PARA_NUM	8
struct aliyun {
	/**/
	char productKey[64];
	char deviceName[64];
	char deviceSecret[64];
	/*para*/
	struct aliyun_para {
		char para_name[48];
		char para_value[16];
	} para[PARA_NUM];
};
extern struct aliyun aliyun_para;

void USART2_RxIdleCallback(UART_HandleTypeDef *huart);
void usart2_rx_deal(USART2_RECEIVETYPE *usart2_rx);

uint8_t mod_para_init(void);
uint8_t mod_read_status(void);
void mod_reset_power(void);
uint8_t mod_open_power(void);
Mod_Status mod_get_conn(void);
void mod_reset(void);
void mqtt_init(void);
Mod_Status mqtt_CGATT(void);
Mod_Status mqtt_CEREG(void);
Mod_Status mqtt_NetClock(void);
Mod_Status mqtt_release(void);
Mod_Status mqtt_aliyun_conn(void);
void mod_deal(void);
